<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Category extends CI_Controller {
	
	public function index() { }

	public function getCat($catId) {
		$this->load->model('Model_category');
		$cursor = $this->Model_category->getCat($catId);

		// Conver mongoCursor to JSON
		echo json_encode($cursor);	
	}

	public function getCatsList() {
		$this->load->model('Model_category');
		$cursor = $this->Model_category->getCats();
		$cursor->sort(array('_id' => 1));

		echo json_encode(iterator_to_array($cursor));
	}

	public function getSection() {
		$this->load->model('Model_category');
		$cursor = $this->Model_category->getSections();
		$arr = array();
		foreach (iterator_to_array($cursor) as $cat) {
			array_push($arr, $cat);
		}
		echo json_encode($arr);
	}

}
